home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dtk_demo.zip / CURRDIR.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  2KB  |  70 lines

  1. /*  CURRDIR.C
  2.  *  last mod.: 31-AUG-91
  3.  */
  4.  
  5. #include <STDIO.H>
  6. #include <STDLIB.H>
  7. #include <STRING.H>
  8.  
  9. #include <L_DIR.H>
  10. #include <L_DISK.H>
  11. #include <L_TIME.H>
  12. #include <L_STR.H>
  13.  
  14. /*-----------*/
  15. void main(void)
  16. {
  17. Uchar high = high_drive();
  18. Uchar drive = 'A';
  19. Uchar last_drive;
  20. Uchar current_directory[68];
  21. int err_flag, num_floppies = num_floppy_drives();
  22.  
  23. if ( num_floppies == 1 )
  24.     last_drive = last_drive_used('A',&err_flag);
  25.  
  26. printf("Drive   Current directory\n");
  27. do  {
  28.     if ( drive <= 'B' && num_floppies == 1
  29.          && ( ( err_flag == -32 && drive == 'B' )
  30.               || ( err_flag != 32 && drive != last_drive ) ) )
  31.         continue;
  32.     printf("  %c     ",drive);
  33.     switch ( get_directory(drive,current_directory) )
  34.         {
  35.         case -1:
  36.             printf("NULL value for path.\n");
  37.             break;
  38.         case -2:
  39.             printf("Invalid drive.\n");
  40.             break;
  41.         case -3:
  42.             printf("Disk not present in floppy disk drive.\n");
  43.             break;
  44.         default:
  45.             puts(current_directory);
  46.         }
  47.     } while ( ++drive <= high );
  48.  
  49. /*  randomly change to a another drive or subdirectory  */
  50. do  {
  51.     drive = (Uchar)( 'A'
  52.         + ((Uchar)time_elapsed_this_decade()%(high-'A'+1)) );
  53.     } while ( drive == 'B'
  54.         || ( drive == 'A' && !bios_disk_present(0) ) );
  55.  
  56. get_directory(drive,current_directory);
  57. if ( strlen(current_directory) > 3 )
  58.     {
  59.     /*  is not root directory; change to parent subdirectory  */
  60.     *strrchr_n(current_directory,'\\',1) = '\0';
  61.     if ( strlen(current_directory) == 2 )
  62.         strcat(current_directory,"\\");
  63.     printf("Changing to %s\n",current_directory);
  64.     }
  65. set_directory(current_directory,TRUE);
  66. /*  TRUE = change drive if different  */
  67. get_directory(drive,current_directory);
  68. printf("Current directory is %s\n",current_directory);
  69. }
  70.